//
//  MineAttentionViewController.m
//  CarLife
//
//  Created by yu on 2019/6/10.
//  Copyright © 2019年 jpas. All rights reserved.
//

#import "MineAttentionViewController.h"
//#import "AttentionCell.h"

#define kAttentionCellIdentifier @"AttentionCellIdentifier"


@interface MineAttentionViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation MineAttentionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = self.mineFocusType == MineFocusTypeAttention ? @"我的关注" : @"我的粉丝";
    [self.tableView registerNib:NIB_NAMED(@"AttentionCell") forCellReuseIdentifier:kAttentionCellIdentifier];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AttentionCell *cell = [tableView dequeueReusableCellWithIdentifier:kAttentionCellIdentifier];
    // 这样设置是不可以的，因为无法区分已关注，关注，相互关注
//    cell.mineFocusType = self.mineFocusType;
    
    if (self.mineFocusType == MineFocusTypeAttention) {
        //设置按钮不同状态下的(已关注，关注，相互关注)状态。
        //关注和粉丝还需要理顺。
    }
    
    @weakify(self);
    [cell setAttentionBlock:^(UIButton * _Nonnull button) {
        @strongify(self);
        // 我的关注：已关注，关注，互相关注
        if (self.mineFocusType == MineFocusTypeAttention) {
            button.selected = !button.selected;
            if (button.selected) {
                [button setImage:IMAGE_NAMED(@"no_focus") forState:UIControlStateNormal];
            } else {
                [button setImage:IMAGE_NAMED(@"focus1") forState:UIControlStateNormal];
            }
        } else {// 我的粉丝：已关注，关注
            button.selected = !button.selected;
            if (button.selected) {
                [button setImage:IMAGE_NAMED(@"focus1") forState:UIControlStateNormal];
            } else {
                [button setImage:IMAGE_NAMED(@"no_focus") forState:UIControlStateNormal];
            }
        }
    }];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PPLog(@"%ld",indexPath.row);
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setWhiteNavigationBar];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self setDefaultNavigationBar];
}

@end
